package sync.model.auto;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 自动上传
 * 
 * @author lili
 * 
 */
public class AntoUpgrade implements Runnable {

	@Override
	public void run() {
		while (true) {
			try {
				System.out.println("提交者...");
				ArrayBlockingQueue<LocalEntity> cache = DataBase.cache;
				LocalEntity entity = cache.take();
				// 取出一个任务，执行上传
				ConcurrentHashMap<String, RemoteEntity> remoteDB = DataBase.remoteDB;
				RemoteEntity rEntity = remoteDB.get(entity.getEntityId());
				rEntity.setValue(entity.getValue());
				System.out.println("↑↑↑↑↑上传修改项，编号：" + entity.getId() + "，修改时间："
						+ entity.getModifyTime().getTime());
				LocalEntity lEntity = DataBase.localDB.get(entity.getId());
				if (lEntity.getStatus().equals("-1")) {// 如果不等于-1，表示该实体有新的修改，那么不应该修改它的状态，新的修改会在下一次被提交
					lEntity.setStatus("0");// 修改状态为同步完成
				}
				Thread.sleep(1000);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
